package com.idata.model.proxyDO;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.idata.model.Builder.DisputePersonBuilder;
import com.idata.model.enums.AssociationTypeEnum;
import com.idata.model.interfaces.HasDisputePersonInfo;
import com.idata.model.interfaces.HasDisputeSource;
import com.idata.model.response.DisputeRelationResponse;
import com.idata.model.utils.DefaultImgUrlManager;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @File GraphAnalysisResponse.Java
 * @Modify Time      @Author    @Version    @Description
 * ------------      -------    --------    -----------
 * 2023/10/10         yd.j      1.0         None
 */

@Data
public class KGBaseDisputeInfoDO implements HasDisputePersonInfo, HasDisputeSource {

    @JsonAlias("caseName")
    @JsonProperty
    protected String disputeSource;

    private Integer relationType;

    private String relationValue;

    private String relationUserName;

    private List<String> associationNameList;

    private Map<String, String> disputePersonList;

    @JsonAlias(value = {"110警情.接警单编号", "协同办案.案件编号"})
    protected String disputeId;

    private String avatarUrl = DefaultImgUrlManager.DEFAULT_DISPUTE_IMG_URL;

    public String getAssociationType() {
        return Optional.ofNullable(AssociationTypeEnum.fromCode(relationType)).map(AssociationTypeEnum::getDesc).orElse("");
    }

    public String getAssociationValue() {
        return relationValue;
    }

    public String getAssociationUserName() {
        return relationUserName;
    }

    @JsonIgnore
    public List<DisputeRelationResponse> getDisputePersonList() {
        return DisputePersonBuilder.transferFromDisputePersonMap(disputePersonList);
    }

    @JsonIgnore
    @Override
    public List<String> getDisputePersonNameList() {
        List<DisputeRelationResponse> tmpDisputeRelationResponse = this.getDisputePersonList();
        if (CollectionUtils.isEmpty(tmpDisputeRelationResponse)) {
            return new ArrayList<>();
        }
        return tmpDisputeRelationResponse.stream().map(DisputeRelationResponse::getName).collect(Collectors.toList());
    }

    @JsonIgnore
    @Override
    public List<String> getDisputePersonIdList() {
        List<DisputeRelationResponse> tmpDisputeRelationResponse = this.getDisputePersonList();
        if (CollectionUtils.isEmpty(tmpDisputeRelationResponse)) {
            return new ArrayList<>();
        }
        return this.getDisputePersonList().stream().map(DisputeRelationResponse::getIdCard).collect(Collectors.toList());
    }
}
